package com.terenac;

import android.content.Context;
import android.hardware.Camera;
import android.view.SurfaceHolder;
import android.view.SurfaceView;

public class CameraSurfaceView extends SurfaceView implements SurfaceHolder.Callback {
	private SurfaceHolder mHolder;
	public Camera camera = null;

	public CameraSurfaceView(Context context) {
		super(context);
		mHolder = getHolder();
		mHolder.addCallback(this);
		mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
		// TODO Auto-generated constructor stub
	}

	public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) {
		Camera.Parameters params = camera.getParameters();
		params.setPreviewSize(getWidth(), getHeight());
		camera.setParameters(params);
		camera.startPreview();
		// TODO Auto-generated method stub
		
	}

	public void surfaceCreated(SurfaceHolder arg0) {		
		try{
			camera=Camera.open();
			camera.setPreviewDisplay(mHolder);
		}
		catch (Exception e){
			
		}
		
		// TODO Auto-generated method stub
		
	}

	public void surfaceDestroyed(SurfaceHolder arg0) {
		camera.stopPreview();
		camera=null;
		
		// TODO Auto-generated method stub
		
	}
	
	public void capture (Camera.PictureCallback jpegHandler){
		camera.takePicture(null, null, jpegHandler);
	}

}
